package com.ljf.daily.makemoneydetail.api.service.impl;

import com.ljf.common.api.service.impl.BasisServiceImpl;
import com.ljf.common.exception.ServiceException;
import com.ljf.common.result.ServiceResultModel;
import com.ljf.common.utils.ServiceResultUtil;
import com.ljf.daily.makemoneydetail.domain.repository.DailyDatMakeMoneyDetailRepository;
import com.ljf.daily.makemoneydetail.domain.service.DailyDatMakeMoneyDetailDomainService;
import com.ljf.daily.makemoneydetail.domain.validator.DailyDatMakeMoneyDetailValidator;
import com.ljf.daily.makemoneydetail.dto.command.DailyDatMakeMoneyDetailAccountAdjustCommand;
import com.ljf.daily.makemoneydetail.dto.command.DailyDatMakeMoneyDetailCommand;
import com.ljf.daily.makemoneydetail.dto.command.DailyDatMakeMoneyDetailImportDataCommand;
import com.ljf.daily.makemoneydetail.dto.command.DailyDatMakeMoneyDetailTemplateImportCommand;
import com.ljf.daily.makemoneydetail.dto.query.DailyDatMakeMoneyDetailQuery;
import com.ljf.daily.makemoneydetail.model.DailyDatMakeMoneyDetail;
import com.ljf.daily.makemoneydetail.service.IDailyDatMakeMoneyDetailService;
import com.ljf.daily.makemoneydetail.vo.DailyDatMakeMoneyDetailImportDataVO;
import com.ljf.daily.makemoneydetail.vo.DailyDatMakeMoneyDetailVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * 赚钱明细记录  服务接口实现
 *
 * @author LJF
 * @since 2024-01-25
 */
@Service
public class DailyDatMakeMoneyDetailServiceImpl extends BasisServiceImpl<DailyDatMakeMoneyDetailDomainService, DailyDatMakeMoneyDetailValidator, DailyDatMakeMoneyDetailRepository, DailyDatMakeMoneyDetailQuery, DailyDatMakeMoneyDetailVO, DailyDatMakeMoneyDetail, DailyDatMakeMoneyDetailCommand> implements IDailyDatMakeMoneyDetailService {

    /**
     * 导入数据接口
     *
     * @param command
     * @return
     * @throws ServiceException
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ServiceResultModel<DailyDatMakeMoneyDetailImportDataVO> importData(DailyDatMakeMoneyDetailImportDataCommand command) throws ServiceException {
        validator.checkImportData(command);
        List<DailyDatMakeMoneyDetailImportDataVO> resultList = new ArrayList<>();
        int count = domainService.importData(command, resultList);
        return ServiceResultUtil.success(resultList, String.format("导入成功【%s】条", count));
    }

    /**
     * 账户调整接口
     *
     * @param command
     * @return
     * @throws ServiceException
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ServiceResultModel accountAdjust(DailyDatMakeMoneyDetailAccountAdjustCommand command) throws ServiceException {
        validator.checkAccountAdjust(command);
        domainService.accountAdjust(command);
        return ServiceResultUtil.success("账户调整完成");
    }

    /**
     * 模板导入接口
     *
     * @param command
     * @return
     * @throws ServiceException
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ServiceResultModel templateImport(DailyDatMakeMoneyDetailTemplateImportCommand command) throws ServiceException {
        validator.checkTemplateImport(command);
        domainService.templateImport(command);
        return ServiceResultUtil.success("模板导入成功");
    }

}
